package org.lanqiao.sjx.dao.impl;

import java.sql.SQLException;
import java.util.List;

import javax.sound.midi.MidiDevice.Info;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.lanqiao.bean.Education;
import org.lanqiao.bean.Item;
import org.lanqiao.sjx.dao.ItemDao;
import org.lanqiao.tools.BaseDao;

public class ItemImpl extends BaseDao implements ItemDao{

	@Override
	public Integer insertItem(Item info) {
		String sql="insert into item (userId,itemName,itemDescription,job,"
				+ "startYear,startMonth,endYear,endMonth,date) values(?,?,?,?,?,?,?,?,Now())";
		try {
			return query.update(sql,info.getUserId(),info.getItemName(),info.getItemDescription(),info.getJob(),
					info.getStartYear(),info.getStartMonth(),info.getEndYear(),info.getEndMonth());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer deleteItem(Integer id,Integer userId) {
	return null;
	}

	@Override
	public List<Item> selectItem(Integer userId) {
		String sql="select * from item where userId=?";
		try {
			return query.query(sql, new BeanListHandler<Item>(Item.class),userId);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Integer updateItem(Item info) {
		String sql="update  item set itemName=?,itemDescription=?,job=?,startYear=?,startMonth=?,endYear=?,endMonth=?,date=Now() "
				+ "where  id=?";
		try {
			return query.update(sql,info.getItemName(),info.getItemDescription(),info.getJob(),info.getStartYear(),info.getStartMonth(),info.getEndYear(),info.getEndMonth(),info.getId());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
